/*********************************************************************
 *    Project Name : trust-uuc-service
 *    Package Name : com.trust.smart.uuc.config
 *    Create  Time : 2021/3/25 10:17
 *    =============================================================
 *    (C) Copyright Trustcro Information Technology Co., Ltd.
 *          Corporation 2018-2021 All Rights Reserved.
 *
 *	  【注意： 本内容仅限于长沙信立诚医药科技有限公司内部使用，禁止转发】
 **********************************************************************/
package com.trust.pams.config;

import com.chasonx.common.config.RedisTemplateUtils;
import com.chasonx.common.filter.UnSafeAccessFilter;
import com.chasonx.common.filter.WebRouterProperties;
import com.chasonx.common.interceptor.GlobalControllerExceptionHandler;
import com.trust.pams.filter.SessionFilter;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.web.servlet.FilterRegistrationBean;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Import;
import org.springframework.web.method.support.HandlerMethodReturnValueHandler;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer;

import java.util.List;

/**
 * @Project : trust-uuc-service
 * @Author : Chasonx<zc.x>
 * @CreateTime : 2021/3/25 10:17
 * @Desc :
 * @Version : 1.0
 */
@Configuration
@Import({WebRouterProperties.class , GlobalControllerExceptionHandler.class})
public class Config implements WebMvcConfigurer {

    @Autowired
    private WebRouterProperties routerProperties;
    @Autowired
    private RedisTemplateUtils redisTemplateUtils;

    @Override
    public void addReturnValueHandlers(List<HandlerMethodReturnValueHandler> handlers) {
    }

    @Bean
    public FilterRegistrationBean accessFilter() {
        UnSafeAccessFilter accessFilter = new UnSafeAccessFilter();
        FilterRegistrationBean registration = new FilterRegistrationBean(accessFilter);
        registration.addUrlPatterns("/*");
        registration.setName("accessFilter");
        registration.setOrder(1);
        return registration;
    }

    @Bean
    public FilterRegistrationBean sessionFilter(){
        SessionFilter sessionFilter = new SessionFilter( routerProperties );
        sessionFilter.setRedisTemplateUtils(redisTemplateUtils);

        FilterRegistrationBean registrationBean = new FilterRegistrationBean(sessionFilter);
        registrationBean.addUrlPatterns("/*");
        registrationBean.setName("sessionFilter");
        registrationBean.setOrder(2);
        return registrationBean;
    }

}
